package org.gemstone.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.come.Frame.ZhuFrame;
import org.come.entity.Goodstable;
import org.come.until.*;

import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



public class GemMakeTabPanel extends JPanel {
	private JLabel[] mountLabel;// 镶嵌框
	private GemMakeTabMouseListener[] MouseListeners;// 镶嵌框
	private JLabel goodsName;

	public GemMakeTabPanel(Goodstable good) {
			this.setPreferredSize(new Dimension(160, 67));
	        this.setOpaque(false);
	        this.setLayout(null);
	        goodsName = new JLabel();
	        goodsName.setBounds(68, 8, 80, 20);
	        goodsName.setForeground(new Color(187, 165, 75));
	        goodsName.setFont(UIUtils.TEXT_HY16);
	        this.add(goodsName);// 添加组件

	        // 组件初始化
	        mountLabel = new JLabel[4];
	        MouseListeners = new GemMakeTabMouseListener[4];
	        mountLabel[0] = new JLabel();
	        mountLabel[0].setBounds(10, 8, 53, 51);
	        MouseListeners[0] = new GemMakeTabMouseListener(null);
	        mountLabel[0].addMouseListener(MouseListeners[0]);
	        this.add(mountLabel[0]);
	        for (int i = 1; i < mountLabel.length; i++) {
	            mountLabel[i] = new JLabel();
	            mountLabel[i].setBounds(68 + (i - 1) * 29, 33, 25, 25);
	            mountLabel[i].setOpaque(false);
	            MouseListeners[i] = new GemMakeTabMouseListener(null);
	            mountLabel[i].addMouseListener(MouseListeners[i]);
	            this.add(mountLabel[i]);
	        }
	        SX(good);

	}

	private Goodstable good;
	private int type;

	/***/
	public void SX(Goodstable good) {
		this.good = good;
		this.type = Goodtype.EquipmentType(good.getType());
		goodsName.setText(type == 0 ? "武器" : type == 3 ? "衣服" : type == 1 ? "帽子" : type == 2 ? "项链" : "鞋子");
		mountLabel[0].setIcon(GoodsListFromServerUntil.imgpathAdaptive(good.getSkin(), 49, 49));
		MouseListeners[0].rgid = good.getRgid();
		for (int i = 1; i < 4; i++) {
			MouseListeners[i].rgid = null;
			mountLabel[i].setIcon(null);
		}
		String extra = AccessSuitMsgUntil.getExtra(good.getValue(), "宝石属性");
		if (extra != null) {
			String[] extras = extra.split("&");
			for (int i = 1; i < extras.length; i++) {
				BigDecimal id = new BigDecimal(extras[i]);
				Goodstable goodstable = GoodsListFromServerUntil.fushis.get(id);
				if (goodstable != null) {
					int path = Goodtype.GemPath(type, goodstable.getType());
					if (path != 0) {
						mountLabel[path].setIcon(CutButtonImage.getGemstoneIcon(goodstable.getSkin(), 25, 25));
						MouseListeners[path].rgid = id;
					}
				}
			}
		}
	}

	private ImageIcon icon1;
	private ImageIcon icon2;

	@Override
	protected void paintComponent(Graphics g) {
		// TODO Auto-generated method stub
		super.paintComponent(g);
			if (type == 0) {
	            if (icon1 == null) {
	                icon1 = new ImageIcon("inkImg/newbackground/B270.png");
	            }
	            g.drawImage(icon1.getImage(), 0, 0, 160, 67, this);
	        } else {
	            if (icon2 == null) {
	                icon2 = new ImageIcon("inkImg/newbackground/B269.png");
	            }
	            g.drawImage(icon2.getImage(), 0, 0, 160, 67, this);
	        }

	}

	class GemMakeTabMouseListener implements MouseListener {
		private BigDecimal rgid;

		public GemMakeTabMouseListener(BigDecimal rgid) {
			super();
			this.rgid = rgid;
		}

		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub

		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub

		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub

		}

		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			if (rgid != null) {
				Goodstable goodstable = GoodsListFromServerUntil.getRgid(rgid);
				if (goodstable != null) {
					ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
					MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
				}
			}
		}

		@Override
		public void mouseExited(MouseEvent e) {
			MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
			// TODO Auto-generated method stub
			ZhuFrame.getZhuJpanel().cleargoodtext();
		}
	}

	public Goodstable getGood() {
		return good;
	}

}
